﻿@{
    Layout = null;
    ViewBag.Title = "角色用户关联——公路工程建设项目造价全过程管理系统";
}
<link rel="stylesheet" href="/Content/zTreeStyle/zTreeStyle.css" type="text/css" />
<link rel="stylesheet" href="/Content/zTreeStyle/zTreeIcons.css" type="text/css" />
<script type="text/javascript" src="/Content/zTreeStyle/jquery.ztree-2.6.min.js"></script>
<script type="text/javascript">
    //----------------------用户-----------------------------
    var zNodes_permission_LinkUser_user = [];
    var zTree_permission_LinkUser_user;
    var setting_permission_LinkUser_user;
    setting_permission_LinkUser_user = {
        checkable: true,
        isSimpleData: true,
        checkedCol: "Checked",
        async: true,
        asyncUrl: "/Permission/Role/GetUserByzTree",
        nameCol: "UserName", //RealName
        treeNodeKey: "Id",
        treeNodeParentKey: "ParentId",
        asyncDataFilter: zTreeOnAsyncSuccess_Permission_role_LinkUser_ajaxDataFilter,
        callback: {
            asyncSuccess: zTreeOnAsyncSuccess_permission_LinkUser_userSelect,
            click: zTreeOnClick_permission_LinkUser_userSelect
        }
    };

    //绑定数据之前对数据进行预处理
    function zTreeOnAsyncSuccess_Permission_role_LinkUser_ajaxDataFilter(treeId, parentNode, childNodes) {
        if (childNodes) {
            var templist = $("#Permission_role_LinkUser_hidden_modulelistID").val().split(',');
            for (var i = 0; i < childNodes.length; i++) {
                for (var j = 0; j < templist.length; j++) {
                    if (childNodes[i].Id == templist[j]) {
                        childNodes[i].Checked = true;
                    }
                }
            }
        }
        return childNodes;
    }

    function zTreeOnAsyncSuccess_permission_LinkUser_userSelect(event, treeId, treeNode, msg) {
        //异步成功
    }

    function zTreeOnClick_permission_LinkUser_userSelect(event, treeId, treeNode) {
        //点击事件
    }
    //-----------------------------------------------------------------

    function Permission_role_linkUser_load() {
        if ($("#Permission_role_linkUser_hidden_role").val() == "") {
            alertMsg.error("请选择角色！");
            $.pdialog.closeCurrent();
            return;
        }
        zTree_permission_LinkUser_user = $("#Permission_role_linkUser_ul_User").zTree(setting_permission_LinkUser_user, zNodes_permission_LinkUser_user);
    }

    //提交的方法
    function Permission_role_linkUser_bindsubmit() {
        $("#Permission_role_linkUser_btn_submit").bind("click", function () {
            //获取角色ID
            submit_roleID = $("#Permission_role_linkUser_hidden_role").val();

            //获取用户ID
            var submit_userNodes = zTree_permission_LinkUser_user.getCheckedNodes(true);
            var submit_userIDs = "";
            for (var i = 0; i < submit_userNodes.length; i++) {
                submit_userIDs += submit_userNodes[i].Id + ",";
            }
            //            if (submit_userIDs == "") {
            //                alertMsg.warn("请选择用户！");
            //                return;
            //            }
            $("#background,#progressBar").show();
            $.ajax({
                url: "/Permission/Role/SetLinkUser",
                dataType: "json",
                type: "post",
                data: { roleID: submit_roleID, userIDs: submit_userIDs },
                success: function (data) {
                    if (data.statusCode == "200") {
                        alertMsg.correct(data.message);
                    }
                    else {
                        alertMsg.error(data.message);
                    }
                    $.pdialog.closeCurrent();
                },
                error: function (e) {
                    alertMsg.error("出现异常，请稍后再试！");
                    $.pdialog.closeCurrent();
                }
            });
            $("#background,#progressBar").hide();
        });
    }

    $(document).ready(function () {
        Permission_role_linkUser_load();
        Permission_role_linkUser_bindsubmit();
    });
</script>
<div class="page" layouth="40">
    <input type="hidden" id="Permission_role_linkUser_hidden_role" value="@ViewBag.roleID" />
    <input type="hidden" id="Permission_role_LinkUser_hidden_modulelistID" value="@ViewData["UserByRole"]" />
    <ul class="searchBar">
        <li>
            <span>角色:</span>
            <i>@ViewBag.roleName</i>
        </li>
    </ul>
    <div class="tabs">
        <div class="tabsHeader">
            <div class="tabsHeaderContent">
                <ul>
                    <li><a href="javascript:void(0)"><span>用 户 </span></a></li>
                </ul>
            </div>
        </div>
        <div class="tabsContent">
            <div layouth="113">
                <ul id="Permission_role_linkUser_ul_User" class="ztree">
                </ul>
            </div>
        </div>
    </div>
</div>
<div class='formBar'>
    <ul>
        <li>
            <button type="submit" class="btn btn-success btn-sm" id="Permission_role_linkUser_btn_submit">
                保存</button></li>
        <li>
            <button type="button" class="close btn btn-default btn-sm">
                取消</button></li>
    </ul>
</div>
